package gui.mainFrame.testConditionViewer.methodInfoViewer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import testGenerator.Controller;

/**
 * Provides panel to view method information.
 * @author William Whitney
 */
public class MethodInfoViewer extends JPanel
{
    private static final long serialVersionUID = 1L;

    private JLabel methodJLabel;
    private JLabel methodNumberJLabel;
    private final Controller controller;

    /**
     * Default constructor.
     * @param controller
     */
    public MethodInfoViewer(Controller controller)
    {

        this.controller = controller;

        //Set class vars
        methodJLabel = new JLabel("");
        methodNumberJLabel = new JLabel("");

        //Setup Layout
        BorderLayout layout = new BorderLayout();
        this.setLayout(layout);
        TitledBorder border = new TitledBorder("Method Information");
        this.setBorder(border);

        //Add Method info to panel
        this.addMethodInfo();

        //Set size
        this.setMaximumSize(new Dimension(1000,120));

        //Update GUI Values
        this.refresh();
    }

    /**
     * Refreshes the panel with new data from the controller.
     */
    public final void refresh()
    {
        this.methodJLabel.setText("Method Name: " + this.controller.getCurrMethod().getAsString());
        this.methodNumberJLabel.setText("Method: " + (this.controller.getCurrMethodIndex() + 1) + "/" + this.controller.getNumMethods());
    }

    /**
     * Adds method information to panel.
     */
    private void addMethodInfo()
    {
        JPanel panel = new JPanel();
        BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS);
        panel.setLayout(layout);

        panel.add(this.methodNumberJLabel);
        panel.add(this.methodJLabel);
        this.add(panel, BorderLayout.WEST);

    }
}
